package su.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import su.demo.annotaition.DataSource;
import su.demo.dao.TeacherMapper;
import su.demo.entity.Teacher;
import su.demo.enums.DataSourceEnum;
import su.demo.service.TeacherService;

import java.util.List;

/**
 * @author SuZuQi
 * @title: TeacherServiceImpl
 * @projectName ssm_multipledatasources
 * @description: TODO
 * @date 2019/9/6
 */
@Service
public class  TeacherServiceImpl implements TeacherService  {

    @Autowired
    private TeacherMapper teacherMapper ;

    @Override
    @DataSource(DataSourceEnum.DEMO2)
    public int addTeacher() {
      try{
          for(int i=1;i<11;i++){
              Teacher teacher = new Teacher(i+"","测试老师_"+i,"这是测试老师_"+i) ;
              teacherMapper.addTeacher(teacher) ;
          }
          return 1 ;
      }catch(Exception e) {
          e.printStackTrace();
          return 0 ;
      }
    }

    @Override
    @DataSource(DataSourceEnum.DEMO2)
    public List<Teacher> queryTeachers() {
       return teacherMapper.queryList() ;
    }
}
